package com.hellobike.haxing.modules.wms.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hellobike.haxing.modules.wms.dto.ExportPickKQDto;
import com.hellobike.haxing.modules.wms.dto.ExportPickZTDDto;
import com.hellobike.haxing.modules.wms.entity.PickHeader;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Description: t_wms_pick_header
 * @Author: haxing-boot
 * @Date: 2020-01-14
 * @Version: V1.0
 */
public interface PickHeaderMapper extends BaseMapper<PickHeader> {

    @Select("SELECT sp.spu_name,sk.sku_code,sk.dimension_values,sk.barcode,d.qty::int as qty,p.partition_code,l.loc_code,e.sku_production_date,d.pick_qty::int as pick_qty " +
            "FROM t_wms_pick_task d  " +
            "LEFT JOIN t_sku as sk ON sk.id=d.sku_id " +
            "LEFT JOIN t_spu as sp ON sp.id=sk.spu_id " +
            "LEFT JOIN t_wms_sku_ext as e ON e.sku_id=d.sku_id " +
            "LEFT JOIN t_wms_location as l ON l.id=d.fm_loc_id " +
            "LEFT JOIN t_wms_partition as p ON p.id=l.partition_id " +
            "WHERE d.deleted=0 AND d.task_type='PK' AND d.doc_type='WV' AND d.doc_oper_id=#{id}")
    List<ExportPickKQDto> exportPickKQ(@Param("id") Long id);

    @Select("SELECT sp.spu_name,sk.dimension_values,sk.sku_code,sk.barcode,d.qty::int as qty,s.shop_name,l.loc_code,d.pick_qty::int as pick_qty  " +
            "FROM t_wms_pick_task d   " +
            "LEFT JOIN t_sku as sk ON sk.id=d.sku_id  " +
            "LEFT JOIN t_spu as sp ON sp.id=sk.spu_id  " +
            "LEFT JOIN t_wms_delivery_order_header o ON o.pick_id=d.doc_oper_id  " +
            "LEFT JOIN t_wms_location as l ON l.id=d.plan_loc_id  " +
            "LEFT JOIN t_shop s ON s.id=o.shop_id  " +
            "WHERE d.deleted=0 AND d.task_type='PK' AND d.doc_type='DO' AND d.doc_oper_id=#{id}")
    List<ExportPickZTDDto> exportPickZTD(@Param("id") Long id);
}
